package com.school.edupoint.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.school.edupoint.config.EduContext;
import com.school.edupoint.model.Activity;
import com.school.edupoint.model.Student;
import com.school.edupoint.model.StudentActivityHistory;
import com.school.edupoint.response.Result;
import com.school.edupoint.service.StudentActivityHistoryService;
import com.school.edupoint.util.ObjectUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/api")
public class StudentActivityHistoryController {
    @Autowired
    private StudentActivityHistoryService studentActivityHistoryService;
    @Autowired
    private EduContext eduContext;

    /**
     * 学生活动记录
     *
     * @param param
     * @return
     * @throws Exception
     */
    @PostMapping("/studentActivityHistory/page")
    public Result<IPage<StudentActivityHistory>> getStudentActivityHistoryPage(@RequestBody Map<String, Object> param) throws Exception {
        String title = (String) param.get("title");
        int pageNum = (int) param.get("pageNum");
        int pageSize = (int) param.get("pageSize");
        System.out.println("当前第" + pageNum + "页");
        System.out.println("一页" + pageSize + "条数据");
        IPage<StudentActivityHistory> studentActivityHistory = studentActivityHistoryService.selectPage(title, pageNum, pageSize);
        System.out.println("活动分页数据为：" + studentActivityHistory);
        return Result.success(studentActivityHistory);
    }


    /**
     * 学生打卡记录
     */
    @PostMapping("/studentActivityHistory/mylist")
    public Result<IPage<StudentActivityHistory>> mylist(@RequestBody Map<String, Object> param) throws Exception {
        String title = (String) param.get("title");
        int pageNum = (int) param.get("pageNum");
        int pageSize = (int) param.get("pageSize");
        System.out.println("当前第" + pageNum + "页");
        System.out.println("一页" + pageSize + "条数据");
        Integer studentId = eduContext.getStudent().getId();
        IPage<StudentActivityHistory> studentIPage = studentActivityHistoryService.mylist(studentId,title,pageNum,pageSize);
        System.out.println(studentIPage);
        return Result.success(studentIPage);
    }




}
